package jdbc.test;

import java.sql.*;

/**
 * @author oldliu
 * @since 1.0
 */
public class AddSubject {
    public static void main(String[] args) {
        try {
            Class.forName("com.mysql.jdbc.Driver");//static{}
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
            return;
        }
        String url = "jdbc:mysql://localhost:3306/java79school?useSSL=false&characterEncoding=UTF-8&serverTimezone=GMT%2b8";
        Connection con = null;
        Statement st = null;
        try {
            con = DriverManager.getConnection(url, "root", "root1234");
            st = con.createStatement();
            String sql = "insert into s_subject(subjectname,classhour,gradeid)values('航母维修',120,3)";
            int i = st.executeUpdate(sql);
            System.out.printf("成功了增加%d行数据", i);
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            try {
                if (st != null)
                    st.close();

            } catch (SQLException e) {
                e.printStackTrace();
            }
            try {
                if (con != null)
                    con.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
}
